/**
 * 功能描述 联盟团信息导航条
 */

define(function (require, exports, module) {
	var Grid = require("grid");
	
	var gridEvents = require("../handler/gridEvents");
	
    var instance = {
        initComponent: function (params, widget) {
            var grid = new Grid({
            	parentNode : ".J-grid",
            	model : {
            		url : "api/planitem/queryalliance",
            		params : function(){
            			var subnav = widget.get("subnav");
            			var obj = {
            				"planItemGroup.alliance" : true,
            				"planItemGroup.planItem.startDate" : subnav.getValue("startDate").start,
            				"planItemGroup.planItem.startDateEnd" : subnav.getValue("startDate").end,
            				fetchProperties : "planItemGroup.planItem.pkPlanItem,planItemGroup.planItem.destination.name," +
            						"planItemGroup.planItem.startDate,planItemGroup.planItem.endDate,signUpNumber," +
            						"planItemGroup.planItem.allianceOrg.name,planItemGroup.planItem.bespeak," +
            						"planItemGroup.planItem.destination.pkDestination,planItemGroup.planItem.allianceOrg.pkAllianceOrg," +
            						"planItemGroup.checkInStatus.*,planItemGroup.pkPlanItemGroup,planItemGroup.version," +
            						"planItemGroup.planItem.version,planItemGroup.planItem.alliance," +
            						"planItemGroup.allianceOrg.name"
            			}
            			if(subnav.getValue("status") != "All"){
            				obj["planItemGroup.checkInStatus"] = subnav.getValue("status");
            			}else{
            				obj["planItemGroup.checkInStatusIn"] = "Initial,Reserve"
            			}
            			return obj;
            		},
            		columns:[{
            			name : "year",
            			label : "年度",
            			format : function(value, row){
            				return moment(row.planItemGroup.planItem.startDate).format("YYYY");
            			},
            		},{
            			name : "planItemGroup.planItem.destination.name",
            			label : "目的地"
            		},{
            			name : "planItemGroup.planItem.startDate",
            			label : "开始日期",
            			format : "date"
            		},{
            			name : "planItemGroup.planItem.endDate",
            			label : "结束日期",
            			format : "date"
            		},{
            			name : "signUpNumber",
            			label : "报名人数"
            		},{
            			name : "planItemGroup.allianceOrg.name",
            			label : "组团单位"
            		},{
            			name : "planItemGroup.checkInStatus.value",
            			label : "状态",
            		},{
                        name : "show",
                        label : "操作",
    					format : "button",
						formatparams : [{
							id : "edit",
							text : "编辑",
							handler : function(index,data,rowEle){
								gridEvents.editData(data, widget);
							}
						},{
							id : "check",
							text : "查看",
							handler : function(index,data,rowEle){
								gridEvents.checkData(data, widget);
							}
						}]
                    },]
        		}
            })
        	widget.set("grid", grid);
        }
    };
    module.exports = instance;
});
